package shop;



//import jadex.bdi.examples.booktrading.common.GuiPanel;
//import jadex.bdi.examples.booktrading.common.Order;
//import jadex.bdi.runtime.AgentEvent;
//import jadex.bdi.runtime.IBDIInternalAccess;
//import jadex.bdi.runtime.IBeliefSetListener;
//import jadex.bdi.runtime.IExpression;
//import jadex.bdi.runtime.IGoal;
import jadex.bdiv3.runtime.ICapability;
//import jadex.bdiv3.runtime.impl.BeliefAdapter;
import jadex.bridge.IComponentStep;
//import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IArgumentsResultsFeature;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.bridge.service.types.clock.IClockService;
//import jadex.commons.SUtil;
//import jadex.commons.future.DelegationResultListener;
//import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
import jadex.commons.gui.SGUI;
import jadex.commons.gui.future.SwingDefaultResultListener;
import jadex.commons.gui.future.SwingResultListener;
import jadex.commons.transformation.annotations.Classname;
import jadex.micro.annotation.Binding;
//import jadex.rules.eca.ChangeInfo;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
//import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
//import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//import java.awt.event.ItemEvent;
//import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DateFormat;
//import java.text.NumberFormat;
//import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
//import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
//import java.util.Iterator;
import java.util.List;
import java.util.Map;

//import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JButton;
//import javax.swing.JCheckBox;
//import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
//import javax.swing.table.DefaultTableModel;

//import shop.CustomerCapability.BuyItem;

/**
 * 
 * @author R
 *
 */
public class ShopPanel extends JPanel {

	// -------- attributes --------

	protected ICapability capa;
	protected Map shops;
	private String itemlabel;
	protected JTable shoptable;
	protected List shoplist = new ArrayList();
	protected AbstractTableModel shopmodel;
	private DateFormat dformat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
    protected String  shopname ;
	
	/**
	 * 构造函数 ，面板组件在这里定义
	 */
	public ShopPanel(final ICapability capa) {
		
		this.capa = capa;
		this.shops = new HashMap();
        //获取实体链表
		try {
			
			//问题，如何那数据
			 shopname = (String)capa.getAgent().getComponentFeature(IArgumentsResultsFeature.class).getArguments().get("shopname");
			 System.out.println("输出参数：" + shopname);

			shoplist = new shop.service.Service().getShopItemInfoByShopName(shopname);
			
			shopmodel = new ItemTableModel(shoplist);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
        //下面开始面板布局
		setLayout(new BorderLayout());
		
		JPanel itempanel = new JPanel(new BorderLayout());//设置一个实体面板
		itempanel.setBorder(new TitledBorder(new EtchedBorder(), "属性"));  // Properties 设置面板属性


		shoptable = new JTable(shopmodel);// 把抽象TableModel添加到Table中
		shoptable.setDefaultRenderer(Object.class, new DefaultTableCellRenderer()
		{
			public Component getTableCellRendererComponent(JTable table,
				Object value, boolean selected, boolean focus, int row, int column)
			{
				Component comp = super.getTableCellRendererComponent(table,
					value, selected, focus, row, column);
				setOpaque(true);
				if(column == 0)
				{
					setHorizontalAlignment(LEFT);
				}
				else
				{
					setHorizontalAlignment(RIGHT);
				}
				if(!selected)
				{
					Object state = shopmodel.getValueAt(row, 6);
					if(ItemInfo.DONE.equals(state))//排序
					{
						comp.setBackground(new Color(211, 255, 156));//设置背景颜色
					}
					else if(ItemInfo.FAILED.equals(state))
					{
						comp.setBackground(new Color(255, 211, 156));//设置背景颜色
					}
					else
					{
						comp.setBackground(table.getBackground());//设置背景
					}
				}
				if(value instanceof Date)
				{
					setValue(dformat.format(value));
				}
				return comp;
			}
		}); 
		shoptable.setPreferredScrollableViewportSize(new Dimension(600, 120));//设置为可以滑动
		JScrollPane scroll = new JScrollPane(shoptable);
		itempanel.add(BorderLayout.CENTER, scroll);// 支持滚动，为位置Center
		shoptable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 单选
		shoptable.addMouseListener(new MouseAdapter() 
		{ // 鼠标事件
					public void mouseClicked(MouseEvent e) {
						int selectedRow = shoptable.getSelectedRow(); // 获得选中行索引
						Object oa = shopmodel.getValueAt(selectedRow, 0);
						Object ob = shopmodel.getValueAt(selectedRow, 1);

					}
				});

		scroll.setViewportView(shoptable);
		
		
		//===========================================================================
  
		
		JPanel south = new JPanel(); 
		// south.setBorder(new TitledBorder(new EtchedBorder(), " Control "));
		JButton add = new JButton("Add");
		final JButton remove = new JButton("Remove");
		final JButton edit = new JButton("Edit");
		final JButton update = new JButton("Update");
		
		add.setMinimumSize(remove.getMinimumSize());
		add.setPreferredSize(remove.getPreferredSize());
		edit.setMinimumSize(remove.getMinimumSize());
		edit.setPreferredSize(remove.getPreferredSize());
		update.setMinimumSize(remove.getMinimumSize());
		update.setPreferredSize(remove.getPreferredSize());
		
		south.add(add);
		south.add(remove);
		south.add(edit);
		south.add(update);
		
		remove.setEnabled(false);
		edit.setEnabled(false);
		
		JSplitPane splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
		splitter.add(itempanel);
		splitter.setOneTouchExpandable(true);
		//splitter.setDividerLocation();
		add(BorderLayout.CENTER, splitter); // 布局的第1部分
		add(BorderLayout.SOUTH, south); // 布局的第2部分


        //下面分别给增删改查添加监听器
		
		//鼠标点击触发
		shoptable.addMouseListener(new MouseAdapter()
		{
			public void mouseClicked(MouseEvent e)
			{
				refreshDetails();
			}
		} );
		
		final InputDialog dia = new InputDialog(true);
		//为添加按钮添加事件,add监听器
		add.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				capa.getAgent().getExternalAccess().scheduleStep(new IComponentStep<Void>()
				{
					@Override
					public IFuture<Void> execute(IInternalAccess ia) 
					{
						ia.getComponentFeature(IRequiredServicesFeature.class).searchService(IClockService.class, Binding.SCOPE_PLATFORM)
						.addResultListener(new SwingDefaultResultListener(ShopPanel.this)
						{
							public void customResultAvailable(Object result) 
							{
								dia.shopname.setText(shopname);  // 设置 add编制 文本框的 商店名
								dia.shopname.setEditable(false);  //设置为 不可以编辑
								
								IClockService cs = (IClockService)result;
								while(dia.requestInput(cs.getTime()))
								{
									try
									{

										String itemName = dia.itemName.getText();//把添加数据的文本框的 商品名 数据拿出来，进行数据库添加操作
										double itemPrice = Double.parseDouble(dia.itemPrice.getText());//把商品价格数据拿出来，进行数据库存储
										int quantity= Integer.parseInt(dia.itemNumber.getText());//把商品数量在文本框中拿出来，进行数据存储操作。
										
										final ItemInfo itemInfo = new ItemInfo(itemName,itemPrice,quantity);
																				
										  
										capa.getAgent().getExternalAccess().scheduleStep(new IComponentStep<Void>()
										{   
											@Classname("add")
											@Override
											public IFuture<Void> execute(IInternalAccess ia) 
											{
											  System.out.println("add输出"+ shopname +"商品名字：" +itemInfo.getName()+ "价格："+itemInfo.getPrice()+"数量："+itemInfo.getQuantity());
											  //IBDIInternalAccess bia = (IBDIInternalAccess)ia;
											  
											  //////////////////////////////////////////////////////////////////////
											  System.out.println(" add 在这里做数据库存储。。。。。");
											  shop.service.Service service = new shop.service.Service();
											  service.addItemInfoByShopName(itemInfo, shopname);
											  /////////////////////////////////////////////////////////////////////
											  
											  return IFuture.DONE;
											}
											
										});
										
										shoplist.add(itemInfo);//添加数据到 pannel 上 
										shopmodel.fireTableDataChanged();//刷新
										
										break;//通过中断，关闭编辑框
							        }
									catch(NumberFormatException e1)
							        {
										 e1.printStackTrace();
							        }
									
						        }
							 }
						});	
					  return IFuture.DONE;
					}
				});
						
				
			}
		});

		shoptable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		shoptable.getSelectionModel().addListSelectionListener(new ListSelectionListener()
		{
			public void valueChanged(ListSelectionEvent e)
			{
				System.out.println("这里是鼠标选择按钮事件");
				boolean selected = shoptable.getSelectedRow() >= 0;
				remove.setEnabled(selected);
				edit.setEnabled(selected);
			}
		});
		
		remove.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.out.println("这里是remove按钮事件");
				int row = shoptable.getSelectedRow();
				if(row >= 0 && row < shoplist.size()){
					
					final ItemInfo item = (ItemInfo)shoplist.remove(row);
					shopmodel.fireTableRowsDeleted(row, row);
					
					capa.getAgent().getExternalAccess().scheduleStep(new IComponentStep<Void>()
					{
						@Classname("remove")
						@Override
						public IFuture<Void> execute(IInternalAccess ia) 
						{
							 //IBDIInternalAccess bia = (IBDIInternalAccess)ia;
						    
							  //////////////////////////////////////////////////////////////////////
							
							  System.out.println("在这里做数据库删除操作！");	
							  shop.service.Service service = new shop.service.Service();
							  service.removeItemInfoByShopName(item, shopname);		
							  
							  /////////////////////////////////////////////////////////////////////
							

							  return IFuture.DONE;
						}
						
					});
					
					
				}
				
			}
		});
		
		
		//新建一个弹出框，edit监听器
		final InputDialog edit_dialog = new InputDialog(true);
		edit.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.out.println("Edit 按钮");
				capa.getAgent().getExternalAccess().scheduleStep(new IComponentStep<Void>()
				{
					@Override
					public IFuture<Void> execute(IInternalAccess ia) {
						ia.getComponentFeature(IRequiredServicesFeature.class).searchService(IClockService.class, Binding.SCOPE_PLATFORM)
						.addResultListener(new SwingDefaultResultListener(ShopPanel.this)
						{
							public void customResultAvailable(Object result) 
							{
								
								IClockService cs = (IClockService)result;
								int row = shoptable.getSelectedRow();
								if(row >= 0 && row < shoplist.size())
								{
									final ItemInfo iteminfo = (ItemInfo)shoplist.get(row);
									

									final ItemInfo oldItemInfo=new ItemInfo();
									oldItemInfo.setName(iteminfo.getName());
									oldItemInfo.setPrice(iteminfo.getPrice());
									oldItemInfo.setQuantity(iteminfo.getQuantity());
									
		
									edit_dialog.shopname.setText(shopname);  //  设置 编制文本框的 商店名
									edit_dialog.shopname.setEditable(false); //设置为不可以编辑
									
									edit_dialog.itemName.setText(iteminfo.getName());//获取商品名，放在文本框中
									edit_dialog.itemPrice.setText(String.valueOf(iteminfo.getPrice()));// 获取商品数量，放在文本框中
									edit_dialog.itemNumber.setText(String.valueOf(iteminfo.getQuantity()));
									//edit_dialog.deadline.setText(dformat.format(iteminfo.getDeadline()));//添加当前时间
									
									while(edit_dialog.requestInput(cs.getTime()))
									{
										try
										{   
											String itemName = edit_dialog.itemName.getText(); //获取修改后的文本框中的 商品名  信息
											double itemPrice = Double.parseDouble(edit_dialog.itemPrice.getText());//获取修改后的文本框中的 商品价格  信息
											int quantity= Integer.parseInt(edit_dialog.itemNumber.getText());//获取修改后的文本框中的 商品数量  信息
											
										    iteminfo.setName(itemName);
										    iteminfo.setPrice(itemPrice);
										    iteminfo.setQuantity(quantity);
										    shopmodel.fireTableDataChanged();
										    

											capa.getAgent().getExternalAccess().scheduleStep(new IComponentStep<Void>()
										    {
												@Override
												public IFuture<Void> execute(IInternalAccess ia) 
												{  
	
													  System.out.println("edit  在这里做数据库存储。。。。。"); 
													  //////////////////////////////////////////////////////////////////////
													  System.out.println(" add 在这里做数据库存储。。。。。");
													  shop.service.Service service = new shop.service.Service();
													  service.editItemInfoByShopName(iteminfo, oldItemInfo , shopname);
													  /////////////////////////////////////////////////////////////////////
													
												  return IFuture.DONE;
												}
										    });

											break;//通过中断，关闭编辑框
											
										}catch(NumberFormatException e1)
										{
											JOptionPane.showMessageDialog(ShopPanel.this, "Price limit must be integer.", "Input error", JOptionPane.ERROR_MESSAGE);
										}
										
									}//#while
								}
								
							}
						});	
					  return IFuture.DONE;
					}
				});
			}
		});
		
		//更新按钮触发器
		update.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				updateDetails();
			}
			
		});
	}

	/**
	 * Method to be called when goals may have changed.
	 */
	public void refresh(IShopService shop) {
		
         System.out.println("数据刷新。。。。。。。。。。。。");
		if (shop != null) {
			shop.getCatalog().addResultListener(
					
					new SwingDefaultResultListener(ShopPanel.this)
					{   // 监听器，监听ShopPanel
						public void customResultAvailable(Object result) {
							int sel = shoptable.getSelectedRow();
							ItemInfo[] aitems = (ItemInfo[]) result;
							shoplist.clear();
							for (int i = 0; i < aitems.length; i++) {
								if (!shoplist.contains(aitems[i])) {
									// System.out.println("added: "+aitems[i]);
									shoplist.add(aitems[i]);
								}
							}
							shopmodel.fireTableDataChanged();
							if (sel != -1 && sel < aitems.length)
								((DefaultListSelectionModel) shoptable
										.getSelectionModel())
										.setSelectionInterval(sel, sel);
						}
					});
		} else {
			SwingUtilities.invokeLater(new Runnable() {
				public void run() {
					shoplist.clear();
					shopmodel.fireTableDataChanged();
				}
			});
		}
	}
	
	
	/////////////////////////////////
	/**
	 *  Refresh the details panel.
	 */
	public void refreshDetails()
	{
		System.out.println("刷新明细表信息。。。。。。。。。。");

	}
	
	/////////////////////////////////
	/**
	 *  update the details panel.
	 */
	public void updateDetails()
	{
		System.out.println("刷新明细表信息  updateDetails()  panel。。。。。。");
		
		capa.getAgent().getExternalAccess().scheduleStep(new IComponentStep<Void>()
		{
			@Override
			public IFuture<Void> execute(IInternalAccess ia) {
				// TODO Auto-generated method stub
				
				SwingUtilities.invokeLater(new Runnable() 
				{
					@Override
					public void run() {
						// TODO Auto-generated method stub

					  //double d=11.0;
					 // shopmodel.setValueAt(d, 1, 1);
					  //System.out.println("输出参数 2 getValueAt(1,1)：�" + shopmodel.getValueAt(1, 1) );
					  //shopmodel.fireTableDataChanged();
                      
					  /**
					   * * 算法实现
					   * 功能： 从数据库中 根据 商店名 获取 该商店的全部商品  并刷新到panel上
					   * 1 ： 用 List 获取商店中的 商品 根据 商店名（商店名通过能力体获取Agent获取） 
					   *      (String)capa.getAgent().getArgument("shopname");
					   * 2 ：  通过shopmodel.setValueAt(aValue, rowIndex, columnIndex);设置panel的值
					   * 3 ： 用shopmodel.fireTableDataChanged();更新数据
					   */
					   shopname = (String)capa.getAgent().getComponentFeature(IArgumentsResultsFeature.class).getArguments().get("shopname");
					   shoplist = new shop.service.Service().getShopItemInfoByShopName(shopname);
					   int columnIndex= shopmodel.getColumnCount();//获取总行数
					   int rowIndex = shopmodel.getRowCount();
					   
					   //测试数据
//					   for (Iterator iterator = shoplist.iterator(); iterator
//							.hasNext();) {
//						ItemInfo object = (ItemInfo) iterator.next();
//						
//						 System.out.println("输出获取数据库的List: " + object.getName() );
//						 System.out.println("输出获取数据库的List: " + object.getPrice() );
//						 System.out.println("输出获取数据库的List: " + object.getQuantity() );
//					}
					   
					   for(int i=0;i < rowIndex; i++){
						   for(int j=0;j<columnIndex;j++){
							   System.out.println("输出panel数据 getValueAt(i,j)：" + shopmodel.getValueAt(i, j));
							   //shopmodel.setValueAt(aValue, i, j);
							   ItemInfo object = (ItemInfo)shoplist.get(i); 
							   if(j==0){ 
								   shopmodel.setValueAt(object.getName(), i, j); 
							   }else if(j==1){
								   shopmodel.setValueAt(object.getPrice(), i, j); 
							   }else if(j==2){
								   shopmodel.setValueAt(object.getQuantity(), i, j); 
							   }
						   }
					   }//.end for
					  
					   
					   shopmodel.fireTableDataChanged();
					}
				});
				
				return IFuture.DONE;
			}
			
		});
	}
	
	
	/**
	 *  Get the frame.
	 */
	public Frame getFrame()
	{
		Container parent = this.getParent();
		while(parent!=null && !(parent instanceof Frame))
			parent = parent.getParent();
		return (Frame)parent;
	}
	
	
	
	//-------- inner classes --------

	/**
	 *  The input dialog.   设置弹出框
	 */
	private class InputDialog extends JDialog
	{
		//private JComboBox orders = new JComboBox();//下拉框
		private JTextField shopname = new JTextField(20); //设置商店名
		private JTextField itemName = new JTextField(20); //title 商品名称文本框
		private JTextField itemNumber = new JTextField(20);// limit 商品数量文本框
		private JTextField itemPrice = new JTextField(20);// start 商品价格文本框
		private JTextField deadline = new JTextField(20);
		private boolean aborted;
		private Exception e;

		InputDialog(final boolean buy)
		{
			super(getFrame(), "明细表单", true);

			// Add some default entries for easy testing of the gui.
			// These orders are not added to the agent (see manager.agent.xml).
			capa.getAgent().getExternalAccess().scheduleStep(new IComponentStep<Void>()
			{
				@Override
				public IFuture<Void> execute(IInternalAccess ia) {
					ia.getComponentFeature(IRequiredServicesFeature.class).searchService(IClockService.class, Binding.SCOPE_PLATFORM)
					.addResultListener(new SwingResultListener<IClockService>(new IResultListener<IClockService>()
					{

						@Override
						public void resultAvailable(IClockService result) {
							// TODO Auto-generated method stub
							try
							{
								System.out.println("这里是  InputDialog 。。。。");
							}catch(Exception exception){
								
							}
							
							JPanel center = new JPanel(new GridBagLayout());//定义中央面板
							center.setBorder(new EmptyBorder(5, 5, 5, 5));//定义中央面板边界位置
							getContentPane().add(BorderLayout.CENTER, center);//编辑面板的相对位编辑面板的相对位置
							
							JLabel label;
							Dimension labeldim = new JLabel("Preset orders ").getPreferredSize();
							int row = 0;
							
							GridBagConstraints leftcons = new GridBagConstraints(0, 0, 1, 1, 0, 0,
									GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0);
							GridBagConstraints rightcons = new GridBagConstraints(1, 0, GridBagConstraints.REMAINDER, 1, 1, 0,
									GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0);
							leftcons.gridy = rightcons.gridy = row++;
							label = new JLabel("商店名");// 属性名-
							label.setMinimumSize(labeldim);// 
							label.setPreferredSize(labeldim);
							center.add(label, leftcons);//把组件添加到中央面板
							center.add(shopname, rightcons);//把多选框组件添加到中央面板
							
							
							
							leftcons.gridy = rightcons.gridy = row++;
							label = new JLabel("商品名"); 
							label.setMinimumSize(labeldim);
							label.setPreferredSize(labeldim);
							center.add(label, leftcons);
							center.add(itemName, rightcons);//添加文本框组件
							
							
							leftcons.gridy = rightcons.gridy = row++;
							label = new JLabel("价格");
							label.setMinimumSize(labeldim);
							label.setPreferredSize(labeldim);
							center.add(label, leftcons);
							center.add(itemPrice, rightcons);//把商品价格文本框,添加到中央面板
							
							
							leftcons.gridy = rightcons.gridy = row++;
							label = new JLabel("数量");
							label.setMinimumSize(labeldim);
							label.setPreferredSize(labeldim);
							center.add(label, leftcons);
							center.add(itemNumber, rightcons);
	
							leftcons.gridy = rightcons.gridy = row++;
							label = new JLabel("时间");
							label.setMinimumSize(labeldim);
							label.setPreferredSize(labeldim);
							center.add(label, leftcons);
							center.add(deadline, rightcons);
							
							////////////////////////////////////////////
							JPanel south = new JPanel();
							// south.setBorder(new TitledBorder(new EtchedBorder(), " Control "));
							getContentPane().add(BorderLayout.SOUTH, south);
							JButton ok = new JButton("Ok");
							JButton cancel = new JButton("Cancel");
							ok.setMinimumSize(cancel.getMinimumSize());
							ok.setPreferredSize(cancel.getPreferredSize());
							south.add(ok);
							south.add(cancel);
							
							
							//确认按钮触发器
							ok.addActionListener(new ActionListener()
							{
								public void actionPerformed(ActionEvent e)
								{   
									System.out.println("OK按钮.......");
									aborted = false;
									setVisible(false);
								}
							});
							//取消按钮，触发器
							cancel.addActionListener(new ActionListener()
							{
								public void actionPerformed(ActionEvent e)
								{
									System.out.println("Cancel按钮.......");
									setVisible(false);
								}
							});
							
//							//下拉选项卡，触发器
//							orders.addActionListener(new ActionListener()
//							{
//								public void actionPerformed(ActionEvent e)
//								{
//									//ItemInfo itemInfo=
//									ItemInfo item = (ItemInfo)orders.getSelectedItem();//拉框选择,选择要选择的下拉选项
//									itemName.setText(item.getName());//添加数据
//									itemNumber.setText("" + String.valueOf(item.getQuantity()));//添加数据
//									itemPrice.setText("" + String.valueOf(item.getPrice()));
//									
//								}
//							});
							
							
						}// #end

						@Override
						public void exceptionOccurred(Exception exception) {
							// TODO Auto-generated method stub
							e	= exception;
						}
                
					}));	
					
				  return IFuture.DONE;
				}
			});
			
			
		}

		public boolean requestInput(long currenttime)
		{
			if(e!=null)
			{
				throw new RuntimeException(e);
			}
			else
			{
				this.deadline.setText(dformat.format(new Date(currenttime + 300000)));
				this.aborted = true;
				this.pack();
				this.setLocation(SGUI.calculateMiddlePosition(getFrame(), this));
				this.setVisible(true);
				return !aborted;
			}
		}
	}
	
	

}
